import ajax from "axios";
import Vue from 'vue'
import store from '../../store/index.js'

const service = ajax.create({
    baseURL:'http://localhost:8094',
    timeout: 1000 * 30,
    withCredentials: false // 允许跨域带token
})

service.interceptors.request.use(config => {
    config.headers['appName'] = store.state.appName;

    if (config.method === "post") {
        if (Object.prototype.toString.call(config.data) === '[object Object]') {
            config.data = Vue.prototype.$qs.stringify({...config.data })
        }
    }
    return config
}, error => {
    return Promise.reject(error)
})

Vue.prototype.$http = service;

